<template>
  <div class="login-page">
    <div class="login-container">
      <h3 class="title">demo项目可视化平台</h3>

      <form @submit.prevent="login">
        <input type="text" v-model="username" placeholder="Username" />
        <input type="password" v-model="password" placeholder="Password" />
        <button type="submit">Login</button>
      </form>

      <div v-if="showSuccess" class="success-message">
        Login Successful
      </div>
      <div v-if="showError" class="error-message">
        Login Failed
      </div>
    </div>
  </div>
</template>
  
<script>
import api from '../assets/axios/awaitapi'
export default {
  data() {
    return {
      username: "",
      password: "",
      showSuccess: false,
      showError: false,
    };
  },
  methods: {
    async login() {
      let res = await api.post("/login",{
        "username":this.username,
        "password":this.password,
      })
      // Simulating login process
      if (res.data.code === 200) {
      // if (this.username === "root" && this.password === "123456") {
        this.showSuccess = true;
        this.showError = false;

        // Redirect to home page after successful login
        this.$router.push("/home");
      } else {
        this.showSuccess = false;
        this.showError = true;
      }
    },
  },
};
</script>
  
<style scoped>
.login-page {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f5f5;
  background: url('@/assets/bg.png') no-repeat;
  background-size: 100vw 100vh;
}

.login-container {
  max-width: 400px;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  text-align: center;
}

input {
  width: 95%;
  padding: 10px;
  margin-bottom: 10px;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.success-message {
  margin-top: 10px;
  color: green;
}

.error-message {
  margin-top: 10px;
  color: red;
}
</style>